import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: syyyy
 * Date: 2025-08-11
 * Time: 15:54
 */
public class MyMinStack {
    public Stack<Integer> stack;
    public Stack<Integer> minStack;

    public MyMinStack() {
        stack=new Stack<>();
        minStack=new Stack<>();
    }

    public void push(int val) {
        stack.push(val);
        if(minStack.empty()){
            minStack.push(val);
        }else{
            if(minStack.peek()>=val){
                minStack.push(val);
            }
        }
    }

    public void pop() {
        if(stack.empty()){
            throw new EmptyStackException();
        }
        if(stack.peek()==minStack.peek()){
            minStack.pop();
        }
        stack.pop();
    }

    public int top() {//是指普通stack的peek()
        if(stack.empty()){
            throw new EmptyStackException();
        }
        return stack.peek();
    }

    public int getMin() {
        if(stack.empty()){
            throw new EmptyStackException();
        }
        return minStack.peek();
    }

}
